package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbResumeinfo;
import com.ruoyi.system.service.ITbResumeinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zhoupeng
 * @description 履历本管理控制层
 * @date 2021/10/11 13:10
 */
@Controller
@RequestMapping("/system/resumeinfo")
public class TbResumeinfoController extends BaseController {

    private String prefix = "system/resumeinfo";

    @Autowired
    private ITbResumeinfoService tbResumeinfoService;

    @RequiresPermissions("system:resumeinfo:view")
    @GetMapping()
    public String resumeinfo(ModelMap mmap) {
        List<String> stationNameList = tbResumeinfoService.selectStationNameList();
        List<String> resumeNameList = tbResumeinfoService.selectResumeNameList();
        List<String> resumeNoList = tbResumeinfoService.selectResumeNoList();
        mmap.put("stationNameList", stationNameList);
        mmap.put("resumeNameList", resumeNameList);
        mmap.put("resumeNoList", resumeNoList);
        return "system/resumeinfo/resumeinfo";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("system:resumeinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbResumeinfo tbResumeinfo) {
        Map<String, Object> params = tbResumeinfo.getParams();
        String time = params.get("beginTime").toString();
        if (StringUtils.isNotEmpty(time)) {
            params.put("beginTime", time.split(" - ")[0]);
            params.put("endTime", time.split(" - ")[1]);
            tbResumeinfo.setParams(params);
        }
        startPage();
        List<TbResumeinfo> list = tbResumeinfoService.selectTbResumeinfoList(tbResumeinfo);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @RequiresPermissions("system:resumeinfo:export")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbResumeinfo tbResumeinfo) {
        List<TbResumeinfo> list = tbResumeinfoService.selectTbResumeinfoList(tbResumeinfo);
        ExcelUtil<TbResumeinfo> util = new ExcelUtil<>(TbResumeinfo.class);
        return util.exportExcel(list, "导出数据");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("system:resumeinfo:add")
    @Log(title = "新增保存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbResumeinfo tbResumeinfo) {
        return toAjax(tbResumeinfoService.insertTbResumeinfo(tbResumeinfo));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        TbResumeinfo tbResumeinfo = tbResumeinfoService.selectTbResumeinfoById(id);
        mmap.put("tbResumeinfo", tbResumeinfo);
        return "system/resumeinfo/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("system:resumeinfo:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbResumeinfo tbResumeinfo) {
        return toAjax(tbResumeinfoService.updateTbResumeinfo(tbResumeinfo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:resumeinfo:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tbResumeinfoService.deleteTbResumeinfoByIds(ids));
    }
}
